package com.zy.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.zy.common.pojo.EUDataGridResult;
import com.zy.common.util.TaotaoResult;
import com.zy.pojo.TbContent;
import com.zy.service.ContentService;

@Controller
public class ContentController {
	@Autowired
	private ContentService contentService;

	@RequestMapping("/content/query/list")
	@ResponseBody
	public EUDataGridResult getContentList(int page,int rows,long categoryId) {
		EUDataGridResult contentList = contentService.getContentList(page, rows, categoryId);
		return contentList;
	}
	
	@RequestMapping("/rest/content/edit")
	@ResponseBody
	public TaotaoResult updateContent(TbContent tbContent) {
		return contentService.updateContent(tbContent);
	}
	
	@RequestMapping("/content/save")
	@ResponseBody
	public TaotaoResult insertContent(TbContent content) {
		TaotaoResult result = contentService.insertContent(content);
		return result;
	}

	@RequestMapping("/content/delete")
	@ResponseBody
	public TaotaoResult deleteContent(String ids) {
		TaotaoResult result=new TaotaoResult();
		if(ids.contains(",")) {
			String[] split = ids.split(",");
			for (String s : split) {
				result = contentService.deleteContent(Long.valueOf(s));
			}
		}else {
			result =contentService.deleteContent(Long.valueOf(ids));
		}
		return result;
	}
}
